import { Component } from '@angular/core';
import { ContactService } from '../api/contact.service';
import { Contact } from './contact';

@Component({
  selector: 'contact',
  template: `<button (click)="getContacts()">联系人</button>
            <div *ngIf="contact">
              <label>姓名</label>
              <input value="{{contact.name}}"/>
              <label>电话</label>
              <input value="{{contact.tel}}"/>
            </div>`,
})

export class ContactComponent {
  contact: Contact;
  constructor(
    private _contactService: ContactService,
  ) {}
  getContacts() {
    this._contactService.getContacts()
      .subscribe((data: Contact) => this.contact = {
        name: data['name'],
        tel: data['tel']
      });
  }
}
